import { defineStore } from 'pinia';
import {reactive} from 'vue';
import {getRoleAccesses} from '@/api/roleAccess';
import generateMenuTree from '@/utils/generateMenuTree';
export const useMenuStore = defineStore('menu',()=>{
    const state = reactive({
        authMenus:[]//经过权限过滤后的用户菜单 
    })
    //根据用户的角色获取此角色对应的菜单
    const getAccessByRoles = async (roles)=>{
        const response = await getRoleAccesses(roles);
        const {access} = response.data;
        state.authMenus=generateMenuTree(access);
        return access;
    }
    return {
        state,
        getAccessByRoles
    }
})